<template>
  <!--商品管理-规格管理 -->
  <div>
    <div>
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="规格名称">
          <el-input
            v-model="formInline.user"
            placeholder="请输入规格名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="searchFn()">搜索</el-button>
          <el-button type="primary" @click="addSpecsShow = true"
            >新增规格</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div>
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        header-cell-class-name="thead"
      >
        <el-table-column prop="date" label="序号" width="180">
          <template slot-scope="scope">
            <b>11111111</b>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="规格名称" width="300">
          <template slot-scope="scope">
            <b>七年级上学期语文专项辅导</b>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="规格1">
          <template slot-scope="scope">
            <p>七年级语文专项辅导-0001</p>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="规格值2">
          <template slot-scope="scope">
            <div class="z-display-flex">
              <p>直播课</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作">
          <template slot-scope="scope">
            <div>
              <a @click="setClassHour()">编辑</a>
              <a @click="addUpdateCourse()">删除</a>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper"
      ></el-pagination>
    </div>
    <el-dialog title="新增规格" :visible.sync="addSpecsShow" width="30%">
      <div>
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="规格名称">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
          <el-form-item
            v-for="(item, index) in form.specs"
            :key="index"
            :label="item.specsName"
          >
            <el-row>
              <el-col :span="21">
                <el-input v-model="item.val"></el-input>
              </el-col>
              <el-col :span="1">&nbsp; </el-col>
              <el-col :span="2">
                <i
                  class="el-icon-delete margin-top5"
                  @click="deleteFormSpecs(item, index)"
                ></i>
              </el-col>
            </el-row>
          </el-form-item>
          <el-form-item label>
            <abbr title="新增规格值"></abbr>
            <el-button
              type="primary"
              @click="addFormSpecs"
              icon="el-icon-plus"
              circle
            ></el-button>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addSpecs()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data () {
    return {
      addSpecsShow: false,
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      form: {
        name: '',
        specs: [{ specsName: '规格值', val: '' }]
      },
      formInline: {
        user: '',
        region: ''
      },
      tableData: [
        {
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        },
        {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1517 弄'
        },
        {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        },
        {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄'
        }
      ]
    }
  },
  methods: {
    deleteFormSpecs (e, index) {
      this.form.specs.splice(index, 1)
    },
    addFormSpecs () {
      this.form.specs.push({ specsName: '规格值', val: '' })
    },
    addSpecs () {
      this.addSpecsShow = false
    },
    addMaterialObject () {
      this.$router.push({ name: 'add-material-object' })
    },
    searchFn () {},
    addGoods () {
      this.$router.push({ name: 'add-goods' })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.queryPageList()
    }
  }
}
</script>
<style scoped>
a {
  cursor: pointer;
}
</style>
